package com.lanou.quanttradedata.stock.job;

import com.lanou.quanttradedata.stock.service.StockService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

@Component
public class StockBasicInfoJob extends QuartzJobBean {
    @Autowired
    private StockService stockService;
    private SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //1、准备需要传递给tuShare 参数
        HashMap<String, String> param = new HashMap<>();
        param.put("exchange","SSE");
        param.put("list_status","L");
        //2、请求 SSE上交所的股票基本信息
        System.out.println("请求SSE上交所的股票基本信息......");
        stockService.saveStockBasicInfoFromNet(param);
        //3、请求 SZSE深交所的股票基本信息
        System.out.println("请求 SZSE深交所的股票基本信息......");
        param.put("exchange","SZSE");
        stockService.saveStockBasicInfoFromNet(param);
        //4、数据更新完毕，删除退市失效数据
        stockService.delStockBasicInfosByOpDate(sdf1.format(new Date()));
    }
}
